﻿using System.Collections.Generic;

namespace DHJ.Cost.CostBooking.Config
{
    /// <summary>
    ///     基本配置
    ///     1.处理方式
    ///     2.子项
    ///     3.Base Map （字段名, excel表头 ）
    ///     4.Extend && Extend Map（字段名, excel表头）
    /// </summary>
    public abstract class CostConfig
    {
        public virtual CostHandleType HandleType => CostHandleType.间接成本处理;

        public abstract int Index { get; }

        private readonly Dictionary<string, string> _map = new Dictionary<string, string>
        {
            {"部门", "部门"},
            {"条码", "条码"},
            {"条码数量", "条码数量"},
            {"成本", "成本"}
        };

        protected virtual Dictionary<string, string> BaseMap => null;

        protected virtual Dictionary<string, string> ExtendMap => null;

        public virtual List<CostConfigItem> Children => new List<CostConfigItem>{new CostConfigItem
        {
            Code = "-",
            Index = 1,
            Title = GetType().Name.Replace("_Config", ""),
            Category = GetType().Name.Replace("_Config", "")
        }};

        public virtual Dictionary<string, string> GetBaseMap()
        {
            if (BaseMap == null)
                return _map;

            foreach (var item in BaseMap)
                if (_map.ContainsKey(item.Key))
                    _map[item.Key] = item.Value;
                else
                    _map.Add(item.Key, item.Value);

            return _map;
        }

        public virtual Dictionary<string, string> GetAllMap()
        {
            if (ExtendMap == null)
                return GetBaseMap();

            var baseMap = GetBaseMap();

            foreach (var item in ExtendMap)
                if (baseMap.ContainsKey(item.Key))
                    baseMap[item.Key] = item.Value;
                else
                    baseMap.Add(item.Key, item.Value);

            return baseMap;
        }
    }
}